<?php
/**
 * Created by PhpStorm.
 * User: stupboy
 * Date: 2018/6/3
 * Time: 0:07
 * Mail:87658989@qq.com
 */

namespace app\adminapi\controller;
use app\base\service\Ding;

class Oschina
{
    public function index(){

        $commit    =  file_get_contents("php://input");
        $commitArr = json_decode($commit,true);
        $messages  = $commitArr['commits'];
        $str       = [];

        foreach($messages as $msg){
            $commitMessage = $msg['message'];
            if( strpos($commitMessage,'api') > 0 || strpos($commitMessage,'接口') > 0 ){
                $str[] = $msg['author']['name'].':'.$msg['message'];
            }
        }
        // 进行钉钉推送
        if(!empty($str)){
            $webHook = 'https://oapi.dingtalk.com/robot/send?access_token=a6a5b1e8afe13e7e46ec9ab4b156895e13910abf0488693787ea593826df870c';
            (new Ding($webHook))->send(implode(',',$str));
        }
    }
}